/*----------------------------------------------------------------------------
* This unit test tests the function fullDeckCount(). 
*----------------------------------------------------------------------------*/

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 0

int main() {

    struct gameState G, preG;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
	int expectDeck, expectHand, expectDiscard, expectCount;
	int actualCount, i = 0, j = 0, card = 0;
	int numPlayer = 2; 
	int seed = rand() % 11;
	SelectStream(1);
	PutSeed((long)seed);
		   
    printf("TESTING fullDeckCount():\n");
	
	for(i = 0; i < numPlayer; i++) { 

		//clear the game state
		G = preG;
		expectDeck = 0, expectHand = 0, expectDiscard = 0, expectCount = 0, actualCount = 0,
	
		//initialize game
		initializeGame(numPlayer, k, seed + i, &G); 
		
		//assign random counts to deck, hand and discard
		G.deckCount[i] = (int)floor(Random() * MAX_DECK);
		G.handCount[i] = (int)floor(Random() * MAX_HAND);
		G.discardCount[i] = (int)floor(Random() * MAX_DECK); //not sure what the max for discard is supposed to be?
		
		//select a card
		card = (int)floor(Random() * treasure_map);
		
		//loop through deck and randomly set the type of cards for deck
		for(j = 0; j < G.deckCount[i]; j++)
		{
			G.deck[i][j] = (int)floor(Random() * treasure_map);
			if(G.deck[i][j] == card) 
				expectDeck++; //increase count if our card is in the deck
		}
		
		//loop through hand and randomly set the type of cards for hand
		for(j = 0; j < G.handCount[i]; j++)
		{
			G.hand[i][j] = (int)floor(Random() * treasure_map);
			if(G.hand[i][j] == card) 
				expectHand++; //increase count if our card is in the hand
		}
				
		//loop through discard and randomly set the type of cards for discard
		for(j = 0; j < G.discardCount[i]; j++)
		{
			G.discard[i][j] = (int)floor(Random() * treasure_map);
			if(G.discard[i][j] == card) 
				expectDiscard++; //increase count if our card is in the hand
		}		
		
		
		expectCount = expectDeck + expectHand + expectDiscard;
		
		actualCount = fullDeckCount(i, card, &G);
		
		if(actualCount == expectCount) {
			printf("fullDeckCount(): PASS when random card and counts assigned to test player %d.\n", i);
			#if (NOISY_TEST == 1)
			printf("\t Details: actualCount = %d, expectCount = %d. \n", actualCount, expectCount);
			#endif		
		}
		else
		{
			printf ("fullDeckCount(): FAIL when random card and counts assigned to  test player %d.\n", i);
			#if (NOISY_TEST == 1)
			printf("\t Details: actualCount = %d, expectCount = %d. \n", actualCount, expectCount);
			#endif	
		}
	}	
	
	
	return 0;
 }
